package cn.agiledata.bank.linkbank.impl.cmb;

import java.math.BigDecimal;
import java.util.Date;

import cn.agiledata.bank.common.util.DateUtil;
import cn.agiledata.bank.linkbank.impl.AbstractBankPayResponse;

/**
 * 中国招商银行支付响应
 * 
 * @author 马贤波
 * 
 */
public final class CmbPayResponse extends AbstractBankPayResponse {

    private static final String[] RESPONSE_KEYS = {
            CmbNetConstant.RETURN_CODE, CmbNetConstant.ORDER_ID,
            CmbNetConstant.AMOUNT, CmbNetConstant.DATE,
            CmbNetConstant.MERCHANT_PARAMETER,
            CmbNetConstant.RETURN_MESSAGE, CmbNetConstant.DIGITAL_SIGN };

    protected AbstractBankPayResponse getCopiedInstance() {
        return new CmbPayResponse();
    }

    protected String[] getValidKeys() {
        return RESPONSE_KEYS;
    }

    protected String getSuccessReturnCode() {
        return CmbNetConstant.RETURN_CODE_SUCCESS;
    }

    public BigDecimal getAmount() {
        try {
            return new BigDecimal(getMessage(CmbNetConstant.AMOUNT));
        } catch (Exception e) {
            return null;
        }
    }

    public boolean isAmountValidatable() {
        return true;
    }

    public String getOrderId() {
        // 获取提交给招商银行的商户参数（交易编号）
        return getMessage(CmbNetConstant.MERCHANT_PARAMETER);
    }

    /**
     * @return 招商银行主机交易日期
     */
    public Date getDate() {
        String dateValue = getMessage(CmbNetConstant.DATE);
        return DateUtil.string2Date(dateValue, CmbNetConstant.DATE_FORMAT);
    }

    public String getReturnCode() {
        return getMessage(CmbNetConstant.RETURN_CODE);
    }

    public String getReturnMessage() {
        return getMessage(CmbNetConstant.RETURN_MESSAGE);
    }

}
